<template>
    <div class="panel-body panel-info">
        <el-tabs v-model="activeName">
            <el-tab-pane name="first">
                <span slot="label"><i class="fa fa-cog"></i> 基础设置</span>
                <el-form v-if="formBase" :model="formBase" class="form" ref="formBase"  label-width="150px">
                    <div class="panel-main">
                        <el-form-item label="网站名称：" prop="site_name">
                            <el-input clearable v-model="formBase.site_name" placeholder="网站名称"></el-input>
                        </el-form-item>
                        <el-form-item label="网站LOGO："
                                      prop="site_logo" >
                            <el-upload
                                class="ad-uploader"
                                :action="upload"
                                :show-file-list="false"
                                name="image"
                                :on-success="uploadSiteLogoSuccess"
                                :before-upload="uploadBefore">
                                <img v-if="formBase.site_logo" :src="formBase.site_logo" class="ad-img site_logo-img">
                                <i v-else class="el-icon-plus ad-uploader-icon"></i>
                                <div slot="tip" class="el-upload__tip">图片大小不能超过 2MB，建议尺寸271:98</div>
                            </el-upload>
                        </el-form-item>
                        <el-form-item label="二维码一："
                                      prop="wechat_one" >
                            <el-upload
                                class="ad-uploader"
                                :action="upload"
                                :show-file-list="false"
                                name="image"
                                :on-success="uploadWechatOneSuccess"
                                :before-upload="uploadBefore">
                                <img v-if="formBase.wechat_one" :src="formBase.wechat_one" class="ad-img wechat-img">
                                <i v-else class="el-icon-plus wechat-uploader-icon"></i>
                                <div slot="tip" class="el-upload__tip">图片大小不能超过 2MB，建议尺寸83:100</div>
                            </el-upload>
                        </el-form-item>
                        <el-form-item label="二维码二："
                                      prop="wechat_two" >
                            <el-upload
                                class="ad-uploader"
                                :action="upload"
                                :show-file-list="false"
                                name="image"
                                :on-success="uploadWechatTwoSuccess"
                                :before-upload="uploadBefore">
                                <img v-if="formBase.wechat_two" :src="formBase.wechat_two" class="ad-img wechat-img">
                                <i v-else class="el-icon-plus wechat-uploader-icon"></i>
                                <div slot="tip" class="el-upload__tip">图片大小不能超过 2MB，建议尺寸83:100</div>
                            </el-upload>
                        </el-form-item>

                        <el-form-item label="售前微信："
                                      prop="wechat" >
                            <el-upload
                                class="ad-uploader"
                                :action="upload"
                                :show-file-list="false"
                                name="image"
                                :on-success="uploadQWechatSuccess"
                                :before-upload="uploadBefore">
                                <img v-if="formBase.qwechat" :src="formBase.qwechat" style="width: 180px;height: 214px;line-height: 214px">
                                <i v-else class="el-icon-plus wechat-uploader-icon" style="width: 180px;height: 214px;line-height: 214px"></i>
                                <div slot="tip" class="el-upload__tip">图片大小不能超过 2MB，建议尺寸180:100</div>
                            </el-upload>
                        </el-form-item>
                        <el-form-item label="标题ICO："
                                      prop="site_ico" >
                            <el-upload
                                class="ad-uploader"
                                :action="upload"
                                :show-file-list="false"
                                name="image"
                                :on-success="uploadIcoSuccess"
                                :before-upload="uploadBefore">
                                <img v-if="formBase.site_ico" :src="formBase.site_ico" class="ad-img wechat-img" style="width: 64px;height: 64px;line-height: 64px">
                                <i v-else class="el-icon-plus wechat-uploader-icon" style="width: 64px;height: 64px;line-height: 64px"></i>
                                <div slot="tip" class="el-upload__tip">图片大小不能超过 2MB,建议做成png格式，尺寸128:128</div>
                            </el-upload>
                        </el-form-item>
                        <el-form-item label="联系电话：" prop="tel">
                            <el-input clearable v-model="formBase.tel" placeholder="联系电话"></el-input>
                        </el-form-item>
                        <el-form-item label="联系邮箱：" prop="email">
                            <el-input clearable v-model="formBase.email" placeholder="联系邮箱"></el-input>
                        </el-form-item>
                        <el-form-item label="研发本部：" prop="address">
                            <el-input clearable v-model="formBase.address" placeholder="研发本部"></el-input>
                        </el-form-item>
                        <el-form-item label="营销中心：" prop="address_two">
                            <el-input clearable v-model="formBase.address_two" placeholder="营销中心"></el-input>
                        </el-form-item>
                        <el-form-item label="城市地址：" prop="address_three">
                            <el-input clearable v-model="formBase.address_three" placeholder="城市地址"></el-input>
                        </el-form-item>
                        <el-form-item label="预约演示：" prop="show_link">
                            <el-input clearable v-model="formBase.show_link" placeholder="预约演示地址"></el-input>
                        </el-form-item>
                        <el-form-item label="百度商桥：" prop="baidu_shangqiao">
                            <el-input clearable v-model="formBase.baidu_shangqiao" placeholder="百度商桥地址"></el-input>
                        </el-form-item>
                    </div>
                    <el-form-item style="padding-left: 150px;margin-top: 50px">
                        <el-button type="primary" @click="update('base')">保 存</el-button>
                    </el-form-item>
                </el-form>
            </el-tab-pane>
            <el-tab-pane name="second">
                <span slot="label"><i class="fa fa-copyright"></i> 版权设置</span>
                <el-form v-if="formIntegral" :model="formIntegral" class="form" ref="formIntegral" label-width="150px">
                    <div class="panel-main">
                        <el-form-item label="版权信息：" prop="copyright">
                            <el-input clearable v-model="formIntegral.copyright" placeholder="版权信息"></el-input>
                        </el-form-item>
                        <el-form-item label="备案号：" prop="record_number">
                            <el-input clearable v-model="formIntegral.record_number" placeholder="备案号"></el-input>
                        </el-form-item>
                        <el-form-item label="备案链接：" prop="record_link">
                            <el-input clearable v-model="formIntegral.record_link" placeholder="备案链接"></el-input>
                        </el-form-item>
                        <el-form-item label="公安备案号：" prop="public_record_number">
                            <el-input clearable v-model="formIntegral.public_record_number" placeholder="公安备案号"></el-input>
                        </el-form-item>
                        <el-form-item label="公安备案链接：" prop="public_record_link">
                            <el-input clearable v-model="formIntegral.public_record_link" placeholder="公安备案链接"></el-input>
                        </el-form-item>
                    </div>
                    <el-form-item style="padding-left: 150px;margin-top: 50px">
                        <el-button type="primary" @click="update('integral')">保 存</el-button>
                    </el-form-item>
                </el-form>
            </el-tab-pane>
        </el-tabs>
    </div>
</template>
<!---->
<script>
import {mapGetters} from 'vuex';
import {ConfigList, ConfigUpdate} from '../../utils/request';
    export default {
        computed: {
            ...mapGetters(['loading', 'upload']),
        },
        data() {
            return {
                activeName: 'first',
                formBase: null,
                formIntegral: null,
            }
        },
        activated() {
            this.config();
        },
        methods: {
            //更新
            update(name){
                let formData;
                switch (name) {
                    case 'base':
                        formData = this.formBase;
                        break;
                    case 'integral':
                        formData = this.formIntegral;
                        break;
                }
                ConfigUpdate(formData).then((res)=>{
                    if(res.code){
                        this.$notify.error({title: 'ERROR', message: res.msg});
                    }else{
                        this.$notify({
                            type: 'success',
                            duration:1000,
                            title: 'SUCCESS',
                            message: res.msg, onClose:()=>{}});
                    }
                });
            },
            config(){
                ConfigList({params: this.params}).then((res)=>{
                    if (res.code) {
                        this.$notify.error({title: 'ERROR', message: res.msg});
                    } else {
                        this.listData = res.data;
                        this.setting(this.listData);
                    }
                })
            },
            uploadIcoSuccess(res) {
                this.formBase.site_ico = res.data.path;
            },
            setting(data){
                this.formBase = {
                    type: 'base',
                    site_name: data.base.site_name,//网站名称
                    site_logo: data.base.site_logo,//网站logo
                    wechat_one: data.base.wechat_one,
                    wechat_two: data.base.wechat_two,
                    site_ico: data.base.site_ico,
                    qwechat: data.base.qwechat,
                    address: data.base.address,
                    address_two: data.base.address_two,
                    address_three: data.base.address_three,
                    tel: data.base.tel,
                    email: data.base.email,
                    show_link: data.base.show_link,
                    baidu_shangqiao: data.base.baidu_shangqiao,
                };
                this.formIntegral = {
                    type: 'integral',
                    copyright: data.integral.copyright,//版权信息
                    record_number: data.integral.record_number,//备案号
                    record_link: data.integral.record_link,//备案链接
                    public_record_number: data.integral.public_record_number,//公安备案号
                    public_record_link: data.integral.public_record_link,//公安备案链接
                };
            },
            uploadSiteLogoSuccess(res) {
                this.formBase.site_logo = res.data.path;
            },
            uploadQWechatSuccess(res){
                this.formBase.qwechat = res.data.path;
            },
            uploadWechatOneSuccess(res) {
                this.formBase.wechat_one = res.data.path;
            },
            uploadWechatTwoSuccess(res) {
                this.formBase.wechat_two = res.data.path;
            },
            uploadBefore(file) {
                const isLt2M = file.size / 1024 / 1024 < 2;
                if (!isLt2M) {
                    this.$message.error('图片大小不能超过 2MB!');
                }
                return isLt2M;
            },
        }
    }
</script>
<style scoped>
.el-icon-plus{
    cursor: pointer;
    font-size: 28px;
    color: #8c939d;
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    text-align: center;
    width: 266px;
    height: 60px;
    line-height: 60px;
}
.img-uploader{
    border: 1px dashed #d9d9d9;
    display: block;
}
.site_logo-img,.site_logo-uploader-icon{
    width: 266px;
    height: 60px;
    line-height: 60px;
}
.wap_logo-img,.wap_logo-uploader-icon{
    width: 100px;
    height: 50px;
    line-height: 50px;
}
.default_avatar-img,.default_avatar-uploader-icon{
    width: 80px;
    height: 80px;
    line-height: 80px;
    border-radius: 50%;
}
.wechat-uploader-icon{
    width: 138px;
    height: 138px;
}
.wechat-img,.wechat-uploader-icon{
    width: 138px;
    height: 138px;
    line-height: 138px;
}
</style>
